class Solution {
public:
    /**
     * @param nums: an integer array and all positive numbers, no duplicates
     * @param target: An integer
     * @return: An integer
     */
    int backPackIV(vector<int> &nums, int target) {
        vector<int> record(target + 1, 0);
        // for (int i = 0; i < nums.size(); ++i)
        // {
        //     record[nums[i]] = 1;  //初始化错误。后面循环每一轮只对一个数考虑取多少次，因此不会出现重复。而这样引入重复！
        // }
        record[0] = 1;
        for (int i = 0; i < nums.size(); ++i)
        {
            for (int j = 0; j <= target - nums[i]; ++j)
            {
                record[j + nums[i]] += record[j];
                cout << j + nums[i] << " " << record[j + nums[i]] << endl;
            }
        }
        return record[target];
    }
};